home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
-
-
- Arithmetic Coding in Turbo Pascal v5.0 ( version 2.0 89/02/27 )
- ---------------------------------------------------------------
-
- The files in the archive with this document comprise a second
- implementation of arithmetic coding, using the algorithms in
- "Arithmetic Coding for Data Compression" by Ian H. Witten,
- Radford M. Neal and John G. Cleary, pp 520 - 540 of June 1987
- Communications of the ACM.
-
- That article gave the encoding and decoding algorithms in C,
- along with two models, a fixed model and an adaptive model.
-
- Also included in this package is a third model from "An Adaptive
- Dependency Source Model For Data Compression" by David M.
- Abrahamson, pp 77 - 83 of January 1989 Communications of the ACM.
-
- The alogrithms presented are designed, as the articles state, for
- clarity and not quickness, but in this second version some effort
- has gone into eliminating the ludicrous. Bit I/O has been folded
- into the arithmetic encoding/decoding units and I/O to the
- character files has been buffered.
-
- The other major change in the second release is the use of
- overlays to let you choose at encode time which of the three
- models to use. Decode automatically detects the model used to
- encode a file and uses the same model to decode the file. This
- is done through the addition of a prefix byte that identifies the
- model being used.
-
- The code is now perceptibly faster, but possibly more obscure.
-
-
- >>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<
- >>>>>>>>>>>> BUG! BUG! BUG! <<<<<<<<<<<<<<<<<<<
- >>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<
-
- There was a bug in the initial release that resulted in four
- consecutive chr(0)'s being encoded correctly, but decoded as
- eof_symbol. If you wish to fix the original release you must
- change the line in DECODE_SYMBOL of arith_de.pas that currently
- reads
-
- cum := ( longint ( value - low + 1 ) ....
-
- to
-
- cum := ( ( longint(value) - low + 1 ) ....
-
- The original line caused arithmetic overflow as TP did not
- promote the expression until value-low+1 was evaluated! And as we
- all know, 65535 - 0 + 1 = 0 !!!
-
- >>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<
- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<
-
-
-
-
-
-
- >>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<
-
- Files in this second release are :
-
- arith.prn : this file
-
- encode.pas : program that encodes a file
- decode.pas : program that decodes a file
-
- arith_en.pas : unit implementing arithmetic encoding
- arith_de.pas : unit implementing arithmetic decoding
- arith_h.pas : unit holding common declarations for encoding and
- decoding
-
- model_h.pas : unit holding declarations for all models
- fix_mod.pas : unit implementing fixed model
- adap_mod.pas : unit implementing adaptive model
- adp_mod.pas : unit implementing adaptive dependency
- source model
-
- Encode now takes three parameters :
-
- encode <model id> <file to encode> <output file>
-
- where <model id> is f (fixed), a (adaptive), or d (adaptive
- dependency).
-
- Decode takes two parameters :
-
- decode <output file> <encoded file>
-
- Note that no parameters are optional now. The source makes it
- clear why I did this.
-
- >>>>> Note <<<<<
-
- The adaptive dependency model uses a LOT of memory - i.e. too
- much to run from the IDE. If you want to run it from the IDE you
- can change no_of_chars in model_h.pas to 128 from 256. This has
- worked for me. You could also modify the allocation of array
- rows for count, etc. to be truly dynamic, i.e. only allocate
- those being used. This has also worked for me.
-
- The compression for the adaptive and adaptive dependency models
- gets better the longer the file is.
-
- For further details on the method and its advantages over most
- others read the articles cited above.
-
- Arithmetic coding is an elegant and easy to understand coding
- method that can compress a longer file to the theoretical limits
- of entropy. Enjoy.
-
- Some sample compressions :
-
-
-
- - 2 -
-
-
-
-
-
-
- file fixed model adaptive model dependency model
- -----------------------------------------------------------------
- arith_de.pas 34.31 % 47.08 % 57.95 %
- arith_de.tpu -51.63 % 37.29 % 43.96 %
-
- notice that the fixed model ( set up for english text ) does very
- badly with a code file - it makes it 50 % bigger!
-
-
- ------------------------------------------------------------------
-
- Implemented by Ken Westerback : CompuServe 73547,3520
-
- version 1.0 released 89/02/19
- version 2.0 released 89/02/27
-
- These programs, units and associated documentation are released
- into the public domain to be used and abused as your whims
- dictate.
-
- Feel free to distribute/incorporate/improve as desired.
-
- >>>>> Use at your own risk! <<<<<
-
- Comments and suggestions welcome via CompuServe.
-
- ------------------------------------------------------------------
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- - 3 -
-